from pyspark import SparkConf,SparkContext
import os
os.environ['PYSPARK_PYTHON'] = "D:/python3/python.exe"

#创建SparkConf类对象
conf = SparkConf().setMaster("local[*]").setAppName("test_spark_app")

#基于SparkConf类对象创建SparkContext对象
sc = SparkContext(conf=conf)

# #通过parallelize方法将python对象加载到Spark内，成为rdd对象
rdd1 = sc.parallelize([1,2,3,4,5])
# rdd2 = sc.parallelize([1,2,3,4,5])
# rdd3 = sc.parallelize("abcdefg")
# rdd4 = sc.parallelize({1,2,3,4,5})
# rdd5 = sc.parallelize({"key1":"value1","key2":"value2"})
# #如果要查看RDD里面的内容，需要用collect()方法
# print(rdd1.collect())
# print(rdd2.collect())
# print(rdd3.collect())
# print(rdd4.collect())
# print(rdd5.collect())

#用textFile方法，读取文件数据加载到Spark内，成为Rdd对象
# rdd = sc.textFile("D:/date.txt")
# print(rdd.collect())





#map方法
def func(data):
    return data*10

rdd2 = rdd1.map(func)
print(rdd2.collect())


sc.stop()